package com.tjbank.cssys.web.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class Aop {
    private  static Logger logger =LoggerFactory.getLogger(Aop.class);

    @Pointcut("execution(* com.tjbank.cssys.web.service..*.*(..))")
    public void datePointCut(){}

    @Around("datePointCut()")
    public Object doAroud(ProceedingJoinPoint joinPoint) throws Throwable {
        long startDateTime=System.currentTimeMillis();
        try {
            Object result=joinPoint.proceed();
            long endTime=System.currentTimeMillis();
            logger.error("-----"+joinPoint+" UserTime:"+(endTime-startDateTime)+"ms!");
            return result;
        } catch (Throwable throwable) {
            long endTime=System.currentTimeMillis();
            logger.error("-----"+joinPoint+" UserTime:"+(endTime-startDateTime)+"ms! with exception:"+throwable.getMessage());
            throw throwable;
        }
    }
}
